﻿using UnityEngine;
using System.Collections;

public class FowardTrigger : FadeTrigger {

	public Square sqr;
	public float prepareTime;

	bool notFighing;
	float leaveBattleTime;

	// Use this for initialization
	void Start () {
		sqr.leader.evtLeadEvent += OnSquareAction;
	}
	
	// Update is called once per frame
	void Update () {
		if (enable)
		{
			if (notFighing)
			{
				leaveBattleTime += Time.deltaTime;
			}

			CheckTrigger();
		}
	}
	
	void CheckTrigger()
	{
		if (leaveBattleTime > prepareTime)
		{
			SkillTriggerMsg msg = new SkillTriggerMsg();
			evtTrigger(this, msg);
		}
	}

	void OnSquareAction(object sender, LeaderMsg msg)
	{
		if (msg.eAction == ELeaderAction.emStopAttack)
		{
			leaveBattleTime = 0;
			notFighing = true;
		}

		if (msg.eAction == ELeaderAction.emAttack)
			leaveBattleTime = 0;
			notFighing = false;
	}
}
